/***************************************************************************
 * Open Object Oriented ANSI C                                             *
 ***************************************************************************
 * Code given under the terms of GNU General Public Licence (GPLv3)        *
 * and without any waranties of any kind including but not limitative to   *
 * waranties on merchandability or any particular applications fitness.    *
 * For more information on GNU/GPL go on :                                 *
 * "http://www.gnu.org/copyleft/gpl.html"                                  *
 *                                                                         *
 * You are allowed to use it for any purposes in the terms of GNU/GPLv3    *
 * (or more).                                                              *
 * This text MUST stay in state on copyed sources (or sources using it)    *
 * and must not be altered.                                                *
 * You are allowed to add your name at the end of the Copylefs list.       *
 ***************************************************************************
 * Copylefts List :                                                        *
 ***************************************************************************
 * 2010-04-16 Patrick PIGNOL <pignol_patrick@hotmail.com> (Original)       *
 * (Type your name here if needed)                                         *
 ***************************************************************************/
#ifndef EVENT_H
#define EVENT_H

#define EVENT_TYPEID 11

typedef struct Event Event;
typedef struct EventInterface EventInterface;
typedef struct EventVirtualTable EventVirtualTable;

#include "Class.h"
#include "EventDelegate.h"
#include "List.h"


struct EventVirtualTable
{
    unsigned long int TypeID;
    EventInterface* Interface;
    ClassVirtualTable* AncestorTable;
    unsigned long int ReferenceCount;
    Event* (*new)(unsigned long pArgsCount, va_list* pParameters);
    EventVirtualTable* (*Initialize)(Event* this, unsigned long pArgsCount, va_list* pParameters);
    void (*Garbage)(Event* this);
    unsigned long int (*TypeOf)(Event* this);
    bool (*IsSameTypeThanTypeID)(Event* this, unsigned long int pTypeID);
    bool (*IsKindOfTypeID)(Event* this, unsigned long int pTypeID);
    bool (*IsSameTypeThan)(Event* this, Class* pSource);
    bool (*IsKindOf)(Event* this, Class* pSource);
};

struct EventInterface
{
    void (*Constructor)(Event* this, unsigned long int pArgsCount, va_list* pParameters);
    void (*Destructor)(Event* this);
    Event* (*Clone)(Event* this);
    void (*AddDelegate)(Event* this, EventDelegate* pDelegate);
    void (*RemoveDelegate)(Event* this, EventDelegate* pDelegate);
    void (*FireEvent)(Event* this, EventArgs* pEventArgs);
};

struct Event
{
    EventVirtualTable* VirtualTable;
    void (*Constructor)(Event* this, unsigned long int pArgsCount, va_list* pParameters);
    void (*Destructor)(Event* this);
    Event* (*Clone)(Event* this);
    Class* aOwner;
    List* aDelegates;
    void (*AddDelegate)(Event* this, EventDelegate* pDelegate);
    void (*RemoveDelegate)(Event* this, EventDelegate* pDelegate);
    void (*FireEvent)(Event* this, EventArgs* pEventArgs);
};

Event* EventNew(unsigned long pArgsCount, va_list* pParameters);
EventVirtualTable* EventInitialize(Event* this, unsigned long pArgsCount, va_list* pParameters);
void EventConstructor(Event* this, unsigned long int pArgsCount, va_list* pParameters);
void EventDestructor(Event* this);
Event* EventClone(Event* this);
void EventAddDelegate(Event* this, EventDelegate* pDelegate);
void EventRemoveDelegate(Event* this, EventDelegate* pDelegate);
void EventFireEvent(Event* this, EventArgs* pEventArgs);

#endif /* EVENT_H*/
